
import java.io.IOException;
import java.net.*;

import websocket4j.server.WebServerSocket;
import websocket4j.server.WebSocket;

public class webSocket {
	
    private WebSocket ws;
    private WebServerSocket socket;
    
    public webSocket(){
    	this.ws = null;
    	this.socket = null;
    }
    
    public void connect(Integer port) {
    	try{
    		this.socket = new WebServerSocket(port);
    	}catch(IOException e){
    		
    	}
    }
    
    public String getMessage(){
    	try {
			return this.ws.getMessage();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public Communication accept(Tv tv){
    	try{
    		if(this.socket == null){
    			System.out.println("socket Null");  			
    		}
    		this.ws = this.socket.accept();
    		return new Communication(this,tv);
    	}catch(IOException e){return null;}
    }
    
    public void sendMessage(String message){
    	try{
    		ws.sendMessage(message);  		
    	}catch(IOException e){}
    }
    
    public void close(){
    	try{
    		ws.close();  		
    	}catch(IOException e){}
    }

}
